package threadlocal

import "github.com/timandy/routine"

// 请求、日志追踪ID
var traceID = routine.NewInheritableThreadLocal[string]()

// 请求登录用户ID
var userID = routine.NewInheritableThreadLocal[string]()

// SetTraceId 设置跟踪ID
func SetTraceId(traceId string) {
	traceID.Set(traceId)
}

// GetTraceId 获取跟踪ID
func GetTraceId() string {
	if traceID.Get() != "" {
		return traceID.Get()
	} else {
		return "<nil>"
	}
}

// SetUserId 设置登录用户ID
func SetUserId(userId string) {
	userID.Set(userId)
}

// GetUserId 获取登录用户ID
func GetUserId() string {
	if userID.Get() != "" {
		return userID.Get()
	} else {
		return ""
	}
}
